<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for reducers/auth.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">all files</a> / <a href="index.html">reducers/</a> auth.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">54.29% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>38/70</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">14.29% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>4/28</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">5.88% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>1/17</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">39.62% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>21/53</span>
      </div>
      <div class='fl pad1y'>
        <span class="strong">5 statements, 1 branch</span>
        <span class="quiet">Ignored</span>  &nbsp;&nbsp;&nbsp;&nbsp;
      </div>
    </div>
  </div>
  <div class='status-line medium'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var jscookie = require('js-cookie')
var request = require('superagent')
&nbsp;
const LOAD = 'redux-example/auth/LOAD';
const LOAD_SUCCESS = 'redux-example/auth/LOAD_SUCCESS';
const LOAD_FAIL = 'redux-example/auth/LOAD_FAIL';
const LOGIN = 'redux-example/auth/LOGIN';
const LOGIN_SUCCESS = 'redux-example/auth/LOGIN_SUCCESS';
const LOGIN_FAIL = 'redux-example/auth/LOGIN_FAIL';
const LOGOUT = 'redux-example/auth/LOGOUT';
const LOGOUT_SUCCESS = 'redux-example/auth/LOGOUT_SUCCESS';
const LOGOUT_FAIL = 'redux-example/auth/LOGOUT_FAIL';
&nbsp;
const initialState = {
  loaded: false
};
&nbsp;
export default <span class="fstat-no" title="function not covered" >function reducer(state = initialState, action = {}) {</span>
<span class="cstat-no" title="statement not covered" >  switch (action.type) {</span>
    case LOAD:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loading: true
      };
    case LOAD_SUCCESS:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loading: false,
        loaded: true,
        user: action.result
      };
    case LOAD_FAIL:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loading: false,
        loaded: false,
        error: action.error
      };
    case LOGIN:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingIn: true
      };
    case LOGIN_SUCCESS:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingIn: false,
        user: action.result
      };
    case LOGIN_FAIL:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingIn: false,
        user: null,
        loginError: action.error
      };
    case LOGOUT:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingOut: true
      };
    case LOGOUT_SUCCESS:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingOut: false,
        user: null
      };
    case LOGOUT_FAIL:
<span class="cstat-no" title="statement not covered" >      return {</span>
        ...state,
        loggingOut: false,
        logoutError: action.error
      };
    default:
<span class="cstat-no" title="statement not covered" >      return state;</span>
  }
}
&nbsp;
export <span class="fstat-no" title="function not covered" >function isLoaded(globalState) {</span>
<span class="cstat-no" title="statement not covered" >  return globalState.auth &amp;&amp; globalState.auth.loaded;</span>
}
&nbsp;
&nbsp;
&nbsp;
export <span class="fstat-no" title="function not covered" >function login(name) {</span>
<span class="cstat-no" title="statement not covered" >  return {</span>
    types: [LOGIN, LOGIN_SUCCESS, LOGIN_FAIL],
    promise: <span class="fstat-no" title="function not covered" >(</span>client) =&gt; client.post('/login', {
      data: {
        name: name
      }
    })
  };
}
&nbsp;
export <span class="fstat-no" title="function not covered" >function logout() {</span>
<span class="cstat-no" title="statement not covered" >  return {</span>
    types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL],
    promise: <span class="fstat-no" title="function not covered" >(</span>client) =&gt; client.get('/logout')
  };
}
&nbsp;
&nbsp;
&nbsp;
// Customized function actions and non-function (standard) actions.
&nbsp;
export <span class="fstat-no" title="function not covered" >function load() {</span>
<span class="cstat-no" title="statement not covered" >  return {</span>
    types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
    promise: <span class="fstat-no" title="function not covered" >(</span>client) =&gt; client.get('/users/load')
  };
}
&nbsp;
&nbsp;
&nbsp;
export <span class="fstat-no" title="function not covered" >function logout_client_func_action() {</span>
<span class="cstat-no" title="statement not covered" >  return <span class="fstat-no" title="function not covered" >(dispatch) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >    jscookie.remove('my_token')</span>
<span class="cstat-no" title="statement not covered" >    dispatch({type: LOGOUT_SUCCESS})</span>
  }
}
&nbsp;
&nbsp;
export <span class="fstat-no" title="function not covered" >function login_func_action(email,password) {</span>
<span class="cstat-no" title="statement not covered" >  return <span class="fstat-no" title="function not covered" >(dispatch) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >    request.post('/auth/local')</span>
           .send({ "email": email, "password": password })
           .end(
<span class="fstat-no" title="function not covered" >                function(err, res){</span>
                    // Calling the end function will send the request
                    
<span class="cstat-no" title="statement not covered" >                    i</span>f (err) {
                      // if err.
<span class="cstat-no" title="statement not covered" >                      console.log(err)</span>
                    } else {
                      // if Login successfully.
<span class="cstat-no" title="statement not covered" >                      console.log(res)</span>
<span class="cstat-no" title="statement not covered" >                      jscookie.set('my_token', res.body.token)</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >                      dispatch({result: res.body.username, type: LOGIN_SUCCESS})</span>
                    }
                }
            )
  }
}
&nbsp;
&nbsp;
export <span class="fstat-no" title="function not covered" >function register_func_action(username, email, password) {</span>
<span class="cstat-no" title="statement not covered" >  return <span class="fstat-no" title="function not covered" >(dispatch) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >    request.post('/api/users')</span>
           .send({ "name": username, "email": email, "password": password })
           .end(
<span class="fstat-no" title="function not covered" >                function(err, res){</span>
                    // Calling the end function will send the request
                    
<span class="cstat-no" title="statement not covered" >                    i</span>f (err) {
                      // if err.
<span class="cstat-no" title="statement not covered" >                      console.log(err)</span>
                    } else {
                      // if Register successfully.
<span class="cstat-no" title="statement not covered" >                      console.log(res)</span>
<span class="cstat-no" title="statement not covered" >                      jscookie.set('my_token', res.body.token)</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >                      dispatch({result: res.body.username, type: LOGIN_SUCCESS})</span>
                    }
                }
            )
  }
}
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Jun 04 2016 17:05:54 GMT+0800 (CST)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
